<template>
	<view class="saveMoney">
		<view class="integral_balance">
			<view class="integral_balance_title">账户余额</view>
			<view class="integral_balance_num">
				<span class="fn-sz-30">￥</span>
				<span>{{ balance ? balance : 0 }}</span>
			</view>
			<view class="top_up_btn"><button class="yellow_btn" @tap="topUP">充值</button></view>
		</view>
		<view class="tab">
			<shortTabs :tabs="tabs" :curTabs="curTabs" @changeTab="changeTab"></shortTabs>
		</view>
		<view class="details_list">
			<view class="details_item" v-for="item in moneyRecordList.lists" :key="item.id">
				<view class="details_info_box">
					<view class="details_name">{{ item.source_string }}</view>
					<view class="details_time">{{ item.create_time }}</view>
				</view>
				<view class="details_num">{{ bill_type == 1 ? '+' : '-' }}{{ item.bill_amt }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import shortTabs from '../../components/shortTabs/shortTabs.vue';
	import com from '../../mixin/index.js';
	export default {
		components: {
			shortTabs
		},
		mixins: [com],
		data() {
			return {
				curTabs: 0,
				tabs: ['收入明细', '支付明细'],
				balance: '',
				moneyRecordList: {
					lists: [],
					total: 1,
					total_page: 0
				},
				page: {
					page: 1,
					page_size: 12
				}
			};
		},
		onLoad() {
			let userInfo = uni.getStorageSync('userInfo');
			this.balance = userInfo.member.coin;
			this.getBillList();
		},
		onReachBottom() {
			this.getBillList();
		},
		methods: {
			changeTab(idx) {
				this.curTabs = idx;
			},
			topUP() {
				uni.navigateTo({
					url: '/pages/mine/topUp?type=coin'
				});
			},
			getBillList() {
				this.getList('moneyRecordList', 'getCoinBillList', 'page', {
					...this.page,
					bill_type: this.bill_type
				});
			}
		},
		watch: {
			curTabs: {
				deep: true,
				handler: function(n, o) {
					console.log(n, o, '变化了');
					this.moneyRecordList = {
						lists: [],
						total: 1,
						total_page: 0
					};
					this.page = {
						page: 1,
						page_size: 4
					};
					this.getBillList();
				}
			}
		},
		computed: {
			bill_type() {
				if (this.curTabs == 0) {
					return 1;
				} else {
					return 2;
				}
			}
		}
	};
</script>

<style lang="scss">
	.saveMoney {
		background-color: #f9f9f9;
		min-height: 100vh;
		padding: 24rpx;

		.integral_balance {
			height: 370rpx;
			box-sizing: border-box;
			background: #ffffff;
			border-radius: 20rpx;
			padding: 46rpx 0;
			text-align: center;
			margin-bottom: 40rpx;

			.integral_balance_title {
				font-size: 30rpx;
				font-weight: 400;
				color: #666666;
				margin-bottom: 20rpx;
			}

			.integral_balance_num {
				font-size: 90rpx;
				font-weight: bold;
				color: #333333;
				margin-bottom: 27rpx;
			}

			.yellow_btn {
				width: 155rpx;
				height: 70rpx;
				line-height: 70rpx;
				margin: 0 auto;
			}
		}

		.tab {
			margin-bottom: 32rpx;
		}

		.details_list {
			.details_item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 128rpx;
				box-sizing: border-box;
				padding: 23rpx 26rpx;
				background: #ffffff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;

				.details_info_box {
					.details_name {
						font-size: 30rpx;
						font-weight: 400;
						color: #333333;
						margin-bottom: 4rpx;
					}

					.details_time {
						font-size: 26rpx;
						font-weight: 400;
						color: #999999;
					}
				}

				.details_num {
					font-size: 36rpx;
					font-weight: bold;
					color: #f34035;
				}
			}
		}
	}
</style>